
"use strict";
// store user action state 
// set, get user state 
function CSPUserMgr () {
	
	this.user_states = [

	];
	
	this.servers = {
		 'hipo': {name:'hipo', serverurl: 'http://k2.emrosswar.com/'} ,
		 'Ania':	{name:'Ania', serverurl: 'http://s103.emrosswar.com/'} ,
		 'tapsg':	{name:'tapsg', serverurl: 'http://k1.tapsg.com/'} ,
	};
	
	this.refs = [

	{ref: 'hhyuna1' ,
		server: 'hipo', 
		users : [
			[ 'iahyuna1', 'hipo', 'hhyuna1', 'e7e83534639343536789426234345228985' ],
			[ 'iahyunb2', 'hipo', 'hhyuna1', 'e7e83534639386783523345232845228985' ],
			[ 'iahyunc3', 'hipo', 'hhyuna1', 'e7e8234452938a343567345232845228985' ],
			[ 'iahyund4', 'hipo', 'hhyuna1', 'e7e82344235235343578962223845228985' ],
			[ 'iahyune5', 'hipo', 'hhyuna1', 'e7e82344235235343687345232845228985' ],
			[ 'iahyunf6', 'hipo', 'hhyuna1', 'e7e34634455235343556745232845228985' ],
			[ 'iahyung7', 'hipo', 'hhyuna1', 'e7e36734455235343453345232845228985' ],
			[ 'iahyunh8', 'hipo', 'hhyuna1', 'e7e36734455234453343345256745228985' ],
			[ 'iahyuni9', 'hipo', 'hhyuna1', 'e7e36734455232342434545232845228985' ],
			[ 'iahyunj0', 'hipo', 'hhyuna1', 'e7e36734455235343523345452325228985' ],
	] },
	// ===== 2nd done
	

/*

	{ref: 'genghiskhan' ,
		server: 'Ania',   
		users : [
			[ 'hgena1', 'Ania', 'genghiskhan', 	'e7e8b613d1b08d0638285712bdb329482ac42982' ],
			[ 'hgenb2', 'Ania', 'genghiskhan', 	'e7e8b613d1b08d0638285712bdb329482ac42982' ],
			[ 'hgenc3', 'Ania', 'genghiskhan',	'e7e8b613d1b08d063828571228589ci9284acf83' ],
			[ 'hgend4', 'Ania', 'genghiskhan',	 'e7e8b613d1b08d06382857122234235236d3af84' ],
			[ 'hgene5', 'Ania', 'genghiskhan',	 'e7e8b613d1b08d0634960934958689a8989b9835' ],
			// [ 'iahyune5', 'hipo', 'genghiskhan', 'e7e82344235235343523345232845228985' ],
	] },*/



	{ref: 'hhyunb2' ,
		server: 'hipo',
		users : [
			[ 'hbhyunh8', 'hipo', 'hhyunb2', 'e7e83523422546745678666234345228985' ],
			[ 'hbhyunj0', 'hipo', 'hhyunb2', 'e7e83523433444245567666234345228985' ],
			[ 'hbhyuni9', 'hipo', 'hhyunb2', 'e7e83523423466678967666234345228985' ],
			[ 'hbhyung7', 'hipo', 'hhyunb2', 'e7e83523422567624545869234345228985' ],
			[ 'hbhyunf6', 'hipo', 'hhyunb2', 'e7e83523422522222267866234345228985' ],
			[ 'hbhyune5', 'hipo', 'hhyunb2', 'e7e83523422523553457895234345228985' ],
			[ 'hbhyuna1', 'hipo', 'hhyunb2', 'e7e83534623524653456726234345228985' ],
			[ 'hbhyunb2', 'hipo', 'hhyunb2', 'e7e83534623524653468745334345228985' ],
			[ 'hbhyunc3', 'hipo', 'hhyunb2', 'e7e83534623522323456567334345228985' ],
			[ 'hbhyund4', 'hipo', 'hhyunb2', 'e7e835346235222345ab567334345228985' ],
	] },



	

	{ref: 'hhyunc3' ,
		server: 'hipo', 
		users : [
			[ 'hchyunj0', 'hipo', 'hhyunc3', 'e7e83535675678976557895334345228985' ],
			[ 'hchyuni9', 'hipo', 'hhyunc3', 'e7e83535675887779678545334345228985' ],
			[ 'hchyunh8', 'hipo', 'hhyunc3', 'e7e83535675675786793545334345228985' ],
			[ 'hchyung7', 'hipo', 'hhyunc3', 'e7e83534856525789995675334345228985' ],
			[ 'hchyunf6', 'hipo', 'hhyunc3', 'e7e83534623525745693545334345228985' ],
			[ 'hchyune5', 'hipo', 'hhyunc3', 'e7e83534623523463567845334345228985' ],
			[ 'hchyund4', 'hipo', 'hhyunc3', 'e7e83534623524825678856234345228985' ],
			[ 'hchyuna1', 'hipo', 'hhyunc3', 'e7e83534623524875677656234345228985' ],
			[ 'hchyunb2', 'hipo', 'hhyunc3', 'e7e83534623524878765346364345228985' ],
			[ 'hchyunc3', 'hipo', 'hhyunc3', 'e7e83534623524224563336364345228985' ],
	] },



	{ref: 'hhyund4' ,
		server: 'hipo', 
		users : [
			[ 'hdhyunj0', 'hipo', 'hhyund4', 'e745657834453466784aab6798787628985' ],
			[ 'hdhyuni9', 'hipo', 'hhyund4', 'e7456578337875679886586798787628985' ],
			[ 'hdhyunh8', 'hipo', 'hhyund4', 'e7456578337878976896586798787628985' ],
			[ 'hdhyung7', 'hipo', 'hhyund4', 'e7456578452325346456896798787628985' ],
			[ 'hdhyunf6', 'hipo', 'hhyund4', 'e7456467897645324784222364345228985' ],
			[ 'hdhyune5', 'hipo', 'hhyund4', 'e7456456623344867834222364345228985' ],
			[ 'hdhyund4', 'hipo', 'hhyund4', 'e7e83534457889909034222890345228985' ],
			[ 'hdhyunc3', 'hipo', 'hhyund4', 'e7e83534623344887684222364345228985' ],
			[ 'hdhyunb2', 'hipo', 'hhyund4', 'e7e83534623524278045645364345228985' ],
			[ 'hdhyuna1', 'hipo', 'hhyund4', 'e7e83534623524678234222364345228985' ],
	] },





	{ref: 'hhyune5' ,
		server: 'hipo', 
		users : [
			[ 'hehyunj0', 'hipo', 'hhyune5', 'e7e83234252342324678a23423424634985' ],
			[ 'hehyuni9', 'hipo', 'hhyune5', 'e7e83532348345836734c23423424634985' ],
			[ 'hehyunh8', 'hipo', 'hhyune5', 'e7e83532348345856734dba883534634985' ],
			[ 'hehyung7', 'hipo', 'hhyune5', 'e7e8353234828abc5684fba883534634985' ],
			[ 'hehyunf6', 'hipo', 'hhyune5', 'e7e8353234828abc8396784a23534634985' ],
			[ 'hehyune5', 'hipo', 'hhyune5', 'e7e83534332a532c3435674a23534634985' ],
			[ 'hehyund4', 'hipo', 'hhyune5', 'e7e835343452a42354b5674a23534634985' ],
			[ 'hehyunc3', 'hipo', 'hhyune5', 'e7e8353464436345bac5234a56734634985' ],
			[ 'hehyunb2', 'hipo', 'hhyune5', 'e7e8353464436345bac5234a56745228985' ],
			[ 'hehyuna1', 'hipo', 'hhyune5', 'e7e83534634578443234222365675228985' ],
	] },
	




	{ref: 'hhyunf6' ,
		server: 'hipo', 
		users : [
			[ 'hfhyunj0', 'hipo', 'hhyunf6', 'e7e4352af34234232354634646345228985' ],
			[ 'hfhyuni9', 'hipo', 'hhyunf6', 'e7e4352af3466345bc67456344345228985' ],
			[ 'hfhyunh8', 'hipo', 'hhyunf6', 'e7e435234ab3245d6c67956344345228985' ],
			[ 'hfhyung7', 'hipo', 'hhyunf6', 'e7e435432423a3456c45456344345228985' ],
			[ 'hfhyunf6', 'hipo', 'hhyunf6', 'e7e4354234234b3453f3456944345228985' ],
			[ 'hfhyune5', 'hipo', 'hhyunf6', 'e7e4354574a564b32423789364345228985' ],
			[ 'hfhyund4', 'hipo', 'hhyunf6', 'e7e83223465678769893522894345228985' ],
			[ 'hfhyunc3', 'hipo', 'hhyunf6', 'e7e83324be4532423423578964345228985' ],
			[ 'hfhyunb2', 'hipo', 'hhyunf6', 'e7e83324be6534534234222389678228985' ],
			[ 'hfhyuna1', 'hipo', 'hhyunf6', 'e7e835346435abd54234222789345228985' ],
	] },



	{ref: 'hhyung7' ,
		server: 'hipo', 
		users : [
			[ 'hghyuni9', 'hipo', 'hhyung7', 'e7e58792323423534554765474345228985' ],
			[ 'hghyunj0', 'hipo', 'hhyung7', 'e7e58792239423423b34566864345228985' ],
			[ 'hghyunh8', 'hipo', 'hhyung7', 'e7e587923234235234745b6864345228985' ],
			[ 'hghyung7', 'hipo', 'hhyung7', 'e7e587923425fe542b34545664345228985' ],
			[ 'hghyunf6', 'hipo', 'hhyung7', 'e7e5879657345ae345334b6864345228985' ],
			[ 'hghyune5', 'hipo', 'hhyung7', 'e7e5464225686793ae65345864345228985' ],
			[ 'hghyund4', 'hipo', 'hhyung7', 'e7e546422342a6563452222364345228985' ],
			[ 'hghyunc3', 'hipo', 'hhyung7', 'e7e546428994fd345452222364345228985' ],
			[ 'hghyunb2', 'hipo', 'hhyung7', 'e7e832345a42fd362452222364345228985' ],
			[ 'hghyuna1', 'hipo', 'hhyung7', 'e7e835342344fd334552222364345228985' ],
	] },
	


	
		{ref: 'hhyunh8' ,
		server: 'hipo', 
		users : [
			[ 'hhhyuna1', 'hipo', 'hhyunh8', 'e7e83534623524345543347687897828985' ], 
			[ 'hhhyunb2', 'hipo', 'hhyunh8', 'e7e83534623524678679679789345228985' ], 
			[ 'hhhyunc3', 'hipo', 'hhyunh8', 'e7e83534234356534597856745645228985' ], 
			[ 'hhhyund4', 'hipo', 'hhyunh8', 'e7e835346235a6d34542523234345228985' ], 
			[ 'hhhyune5', 'hipo', 'hhyunh8', 'e7e83534623534634543538934345228985' ], 
			[ 'hhhyunj0', 'hipo', 'hhyunh8', 'e7e83532356ia889e856785334345228985' ], 
			[ 'hhhyuni9', 'hipo', 'hhyunh8', 'e7e834898a898f567b87895334345228985' ], 
			[ 'hhhyunh8', 'hipo', 'hhyunh8', 'e7e8353567567574789342a909e89888985' ], 
			[ 'hhhyung7', 'hipo', 'hhyunh8', 'e7e835348b3256a435567d5334345228985' ], 
			[ 'hhhyunf6', 'hipo', 'hhyunh8', 'e7e8353462352c2346792e6534545228985' ] 
	] },


			
	
		// {ref: 'hhyuni9' ,
		{ref: '__yuni9' ,
			server: 'hipo', 
			users : [
				[ 'hihyunc3', 'hipo', 'hhyuni9', 'e7e83545756874578784566745645228985' ] ,
				[ 'hihyunj0', 'hipo', 'hhyuni9', 'e7e83532356ia2342357845644345228985' ], 
				[ 'hihyuni9', 'hipo', 'hhyuni9', 'e7e83489823434598345475334345228985' ], 
				[ 'hihyunh8', 'hipo', 'hhyuni9', 'e7e83535675675743525674354576578985' ],  
				[ 'hihyung7', 'hipo', 'hhyuni9', 'e7e835348b3256568734576334345228985' ], 
				[ 'hihyunf6', 'hipo', 'hhyuni9', 'e7e835346278934345452e3453567828985' ], 
				[ 'hihyune5', 'hipo', 'hhyuni9', 'e7e83534667834634457456667867228985' ],
				[ 'hihyund4', 'hipo', 'hhyuni9', 'e7e83534626785345542523234525423985' ],
				[ 'hihyuna1', 'hipo', 'hhyuni9', 'e7e83534623454363463347687457828985' ], 
				[ 'hihyunb2', 'hipo', 'hhyuni9', 'e7e83534623345457664756459334532985' ], 
				] },
				
	
/*
		{ref: 'terminator2' ,
		server: 'hipo', 
		users : [
			[ 'dominate', 'hipo', 'greateload', 'e7e83532356ia2342354545334345228985' , '1212'], 
			] },
		{ref: 'terminator3' ,
		server: 'hipo', 
		users : [
			[ 'extinctor', 'hipo', 'greateload', 'e7e83545756876978677856745645228985' , '1212'] ,
			] },*/

			
/*

	
		{ref: 'wipe9out' ,
		server: 'hipo', 
		users : [
			[ 'hwipea1', 'hipo', 'wipe9out', 'e7e83534623524c23543347687897828985' ], 
			[ 'hwipeb2', 'hipo', 'wipe9out', 'e7e83534623524678679679789345228985' ], 
			[ 'hwipec3', 'hipo', 'wipe9out', 'e7e83534234356578797856745645228985' ], 
			[ 'hwiped4', 'hipo', 'wipe9out', 'e7e835346235abd34542523234345228985' ], 
			// [ 'hwipee5', 'hipo', 'wipe9out', 'e7e83534623534634543534634345228985' ], 
			// [ 'hwipef6', 'hipo', 'wipe9out', 'e7e83532356ia889e854545334345228985' ], 
			// [ 'hwipeg7', 'hipo', 'wipe9out', 'e7e834898a898f898b87895334345228985' ], 
			// [ 'hwipeh8', 'hipo', 'wipe9out', 'e7e8353567567574352342a909e89888985' ], 
			// [ 'hwipei9', 'hipo', 'wipe9out', 'e7e835348b3256a435634d5334345228985' ], 
			// [ 'hwipej0', 'hipo', 'wipe9out', 'e7e8353462352c2345452e6534545228985' ] 
	] },
	
		{ref: 'dominate' ,
		server: 'hipo', 
		users : [
			[ 'hdomia1', 'hipo', 'dominate', 'e7e83534346543623543347687897828985' ], 
			[ 'hdomib2', 'hipo', 'dominate', 'e7e83534623524645746459789345228985' ], 
			[ 'hdomic3', 'hipo', 'dominate', 'e7e83533454356578797856745645228985' ], 
			[ 'hdomid4', 'hipo', 'dominate', 'e7e835346235abd34542523567456228985' ], 
			// [ 'hdomie5', 'hipo', 'dominate', 'e7e83534345574634543534634345228985' ], 
			// [ 'hdomif6', 'hipo', 'dominate', 'e7e83532356ia889e456345334345228985' ], 
			// [ 'hdomig7', 'hipo', 'dominate', 'e7e83483464564598b87895334345228985' ], 
			// [ 'hdomia1', 'hipo', 'dominate', 'e7e8353567563453452342a909e89888985' ], 
			// [ 'hdomia1', 'hipo', 'dominate', 'e7e835348b3256a435634d3453345228985' ], 
			// [ 'hdomia1', 'hipo', 'dominate', 'e7e835334534543634452e6534545228985' ] 
	] },

	{ref: 'extinctor' ,
		server: 'hipo', 
		users : [
			[ 'hexta1', 'hipo', 'extinctor', 'e7e58792323423534554764574345228985' ],
			[ 'hextb2', 'hipo', 'extinctor', 'e7e58792239423423b345b6864345228985' ],
			[ 'hextc3', 'hipo', 'extinctor', 'e7e58792323423523b345b6864345228985' ],
			[ 'hextd4', 'hipo', 'extinctor', 'e7e587923425fe542b345b6864345228985' ],
			// [ 'hexte5', 'hipo', 'extinctor', 'e7e5879657345ae345345b6864345228985' ],
			// [ 'hextf6', 'hipo', 'extinctor', 'e7e5464225686793ae65756864345228985' ],
			// [ 'hextg7', 'hipo', 'extinctor', 'e7e546422342a65645b2222364345228985' ],
			// [ 'hexth8', 'hipo', 'extinctor', 'e7e546428994fd342452222364345228985' ],
			// [ 'hexti9', 'hipo', 'extinctor', 'e7e832345a42fd342452222364345228985' ],
			// [ 'hextj0', 'hipo', 'extinctor', 'e7e835342344fd342452222364345228985' ],
	] },

		{ref: 'honor' ,
		server: 'hipo', 
		users : [
			[ 'veroa1', 'hipo', 'hun9634', 'e7e83534639323445346343523434228985' ],
			[ 'feelc3', 'hipo', 'feelcool', 'e7e83534632342523243234289934228985' ],
			// [ 'feelb2', 'hipo', 'feelcool', 'e7e83534639323423523425345234228985' ],
			// [ 'feela1', 'hipo', 'feelcool', 'e7e83534639345234235324234234228985' ],
			// [ 'kirixa1', 'hipo', 'dkzbffk11', 'e7e8353463938a343543534234234228985' ],
			// [ 'zzoa1', 'hipo', 'LCS2025', 'e7e83532345345234234245334345228985' ], 
			// [ 'kirea1', 'hipo', 'rea', 'e7e83532342652342354545334345228985' ], 
			// [ 'kireb2', 'hipo', 'rea', 'e7e83532346456457457445334345228985' ], 
			// [ 'kirec3', 'hipo', 'rea', 'e7e83532356ia2342356346334345228985' ], 
			// [ 'seria1', 'hipo', 'xxxxx', 'e7e83545645645323423423334345228985' ], 
			// [ 'serib2', 'hipo', 'xxxxx', 'e7e83532567856876876545334345228985' ], 
			] },
	*/

		{ref: 'hhyunj0' ,
		server: 'hipo', 
		users : [
			[ 'ijhyunh8', 'hipo', 'hhyunj0', 'e7e36734455234453343345232845228985' ],
			[ 'ijhyunj0', 'hipo', 'hhyunj0', 'e7e36734455235343523345232325228985' ],
			[ 'ijhyuni9', 'hipo', 'hhyunj0', 'e7e36734455232342423345232845228985' ],			
			// [ 'ijhyuni9', 'hipo', 'hhyunj0', 'e7e36734455232342423345232845228985' ],
			// [ 'ijhyunj0', 'hipo', 'hhyunj0', 'e7e36734455235343523345232325228985' ],
			[ 'ijhyung7', 'hipo', 'hhyunj0', 'e7e36734455235343523345232845228985' ],
			[ 'ijhyunf6', 'hipo', 'hhyunj0', 'e7e34634455235343523345232845228985' ],
			[ 'ijhyune5', 'hipo', 'hhyunj0', 'e7e82344235235343523345232845228985' ],
			[ 'ijhyund4', 'hipo', 'hhyunj0', 'e7e82344235235343523462223845228985' ],
			[ 'ijhyunb2', 'hipo', 'hhyunj0', 'e7e8353463938a343523345232845228985' ],
			[ 'ijhyuna1', 'hipo', 'hhyunj0', 'e7e83534639343536523426234345228985' ],
			[ 'ijhyunc3', 'hipo', 'hhyunj0', 'e7e8234452938a343523345232845228985' ],
	] },
	
				
	{ref: 'jugc' ,		// greatkhan 1 ? 
		server: 'hipo', 
		users : [
			[ 'hjub2', 'hipo', 'jugc', 'e7e83534623524653433545334345228985' ],
			[ 'hjua1', 'hipo', 'jugc', 'e7e83523433444245646666234345228985' ],
			[ 'hjud4', 'hipo', 'jugc', 'e7e835346235222345abc89334345228985' ],
			[ 'hjug7', 'hipo', 'jugc', 'e7e83523422567624545666234345228985' ],
			[ 'hjue5', 'hipo', 'jugc', 'e7e83523422523553453426234345228985' ],
			[ 'hjuf6', 'hipo', 'jugc', 'e7e83523422522222245666234345228985' ],		
			[ 'hjuj0', 'hipo', 'jugc', 'e7e83534623524653453426234345228985' ],
			[ 'hjuh8', 'hipo', 'jugc', 'e7e83523422546745646666234345228985' ],
			[ 'hjui9', 'hipo', 'jugc', 'e7e83523423466645646666234345228985' ],
			[ 'hjuc3', 'hipo', 'jugc', 'e7e83534623522323454564564345228985' ],
	] },
	
	{ref: 'hjua1' ,
		server: 'hipo', 
		users : [
			[ 'hajua1', 'hipo', 'hjua1', 'e7e83534623524879767656234345228985' ],
			[ 'hajub2', 'hipo', 'hjua1', 'e7e83534623524879735346364345228985' ],
			[ 'hajuc3', 'hipo', 'hjua1', 'e7e83534623524222333336364345228985' ],
			[ 'hajud4', 'hipo', 'hjua1', 'e7e83534623524824378856234345228985' ],
			[ 'hajue5', 'hipo', 'hjua1', 'e7e83534623523463543545334345228985' ],
			[ 'hajuj0', 'hipo', 'hjua1', 'e7e835356753535638eb872334345228985' ],
			[ 'hajuf6', 'hipo', 'hjua1', 'e7e83534623525789993545334345228985' ],
			[ 'hajug7', 'hipo', 'hjua1', 'e7e83534856525789993545334345228985' ],
			[ 'hajuh8', 'hipo', 'hjua1', 'e7e83535675675789993545334345228985' ],
			[ 'hajui9', 'hipo', 'hjua1', 'e7e83535675887779993545334345228985' ],
	] },

		{ref: 'hjub2' ,
		server: 'hipo', 
		users : [
			[ 'hbjuj0', 'hipo', 'hjub2', 'e7e83534623524562333336364345228985' ],
			[ 'hbjuh8', 'hipo', 'hjub2', 'e7e83534623524879767656234545228985' ],
			[ 'hbjua1', 'hipo', 'hjub2', 'e7e83535675678976534545334345228985' ],
			[ 'hbjub2', 'hipo', 'hjub2', 'e7e83535675887779934545334345228985' ],
			[ 'hbjuc3', 'hipo', 'hjub2', 'e7e83535675675789964523334345228985' ],
			[ 'hbjud4', 'hipo', 'hjub2', 'e7e83534852355789993545334345228985' ],
			[ 'hbjue5', 'hipo', 'hjub2', 'e7e83534623525789993545654345228985' ],
			[ 'hbjuf6', 'hipo', 'hjub2', 'e7e83534623523443543545334345228985' ],
			[ 'hbjug7', 'hipo', 'hjub2', 'e7e83534623565424378856234345228985' ],
			[ 'hbjui9', 'hipo', 'hjub2', 'e7e83534623524234735346364345228985' ],
		] },
		
			{ref: 'hjuc3' ,
		server: 'hipo', 
		users : [
			[ 'hcjua1', 'hipo', 'hjuc3', 'e745657834453462234aab6798787628985' ],
			[ 'hcjub2', 'hipo', 'hjuc3', 'e7456578337878989886586798787628985' ],
			[ 'hcjuc3', 'hipo', 'hjuc3', 'e7456578337878989886586798787628985' ],
			[ 'hcjud4', 'hipo', 'hjuc3', 'e7456578452325346456586798787628985' ],
			[ 'hcjue5', 'hipo', 'hjuc3', 'e7456467897645324234222364345228985' ],
			[ 'hcjuf6', 'hipo', 'hjuc3', 'e7456456623344887234222364345228985' ],
			[ 'hcjug7', 'hipo', 'hjuc3', 'e7e83534457889909034222364345228985' ],
			[ 'hcjuh8', 'hipo', 'hjuc3', 'e7e83534623344887234222364345228985' ],
			[ 'hcjui9', 'hipo', 'hjuc3', 'e7e83534623524226745645364345228985' ],
			[ 'hcjuj0', 'hipo', 'hjuc3', 'e7e83534623524223234222364345228985' ],
				] },
				
				
				/*
					TAP SG :: 
				*/
			{ref: 'mp001' ,
		server: 'tapsg', 
		users : [
			[ 'hmpa1', 'tapsg', 'mp001', 'e745657834453462234aab6798787628985' , '12', 'tapsg'],
			[ 'hmpb2', 'tapsg', 'mp001', 'e7456578337878989886586798787628985' ,'12',  'tapsg'],
			// [ 'hmpc3', 'tapsg', 'mp001', 'e7456578337878989886586798787628985' , '12', 'tapsg'],
			// [ 'hmpd4', 'tapsg', 'mp001', 'e7456578452325346456586798787628985' , '12', 'tapsg'],
				] },
	/*
			{ref: 'hjuc3_2' ,
			server: 'hipo', 
			users : [
				[ 'hcjuc3', 'hipo', 'hjuc3', 'e7456578337878989886586798787628985' ],
				[ 'hcjud4', 'hipo', 'hjuc3', 'e7456578452325346456586798787628985' ],
					] },
				{ref: 'hjuc3_3' ,
			server: 'hipo', 
			users : [
				[ 'hcjue5', 'hipo', 'hjuc3', 'e7456467897645324234222364345228985' ],
				[ 'hcjuf6', 'hipo', 'hjuc3', 'e7456456623344887234222364345228985' ],
					] },
				{ref: 'hjuc3_4' ,
			server: 'hipo', 
			users : [
				[ 'hcjug7', 'hipo', 'hjuc3', 'e7e83534457889909034222364345228985' ],
				[ 'hcjuh8', 'hipo', 'hjuc3', 'e7e83534623344887234222364345228985' ],
					] },
				{ref: 'hjuc3_5' ,
			server: 'hipo', 
			users : [
				[ 'hcjui9', 'hipo', 'hjuc3', 'e7e83534623524226745645364345228985' ],
				[ 'hcjuj0', 'hipo', 'hjuc3', 'e7e83534623524223234222364345228985' ],
					] },*/
	
				
				
			{ref: 'greatkhan' ,
		server: 'hipo', 
		users : [
			[ 'ggka1', 'hipo', 'greatkhan', 'e745634634523562234aab6798787628985' ],
			[ 'ggkb2', 'hipo', 'greatkhan', 'e7456578356576587686586798787628985' ],
			[ 'ggkc3', 'hipo', 'greatkhan', 'e7456578337877809808986798787628985' ],
			[ 'ggkd4', 'hipo', 'greatkhan', 'e7456578452325346456556765787628985' ],
			[ 'ggke5', 'hipo', 'greatkhan', 'e7456467895675654234222364345228985' ],
			[ 'ggkf6', 'hipo', 'greatkhan', 'e7456456623345656765865364345228985' ],
			[ 'ggkg7', 'hipo', 'greatkhan', 'e7e83534354659909034222364345228985' ],
			[ 'ggkh8', 'hipo', 'greatkhan', 'e7e83534623344887234222567565228985' ],
			[ 'ggki9', 'hipo', 'greatkhan', 'e7e83534623524564745645364345228985' ],
			[ 'ggkj0', 'hipo', 'greatkhan', 'e7e83556756856723234222364345228985' ],
				] },
	];

	
	// 2nd generation  : hhyuna1
			// 0 : name,  1: server, 2 : ref , 3: dev code 
	// default  array.. 
/*
	this.sp_users = [
		'hhyune5',
		'hhyunf6'
	];*/

	
	// this.initialize();
};


CSPUserMgr.prototype = {
	objName: 'CSPUserMgr',
	
	
	initialize: function() {
	},
	
	makeUserDB: function() {
		var self = this;
		// make user info  &  append db  :
		$.each ( this.sp_users , function(i, u) {
			
			// add name 
			CDB.users.push( u[0] );	// naem 
			// add user data
			var server_info = self.servers [ u[1] ];
			
			var passwd = '12';
			if ( u[4]) {
				passwd = u[4];
			}
					
			// set game type 
			var game_type = 'emross';
			if (  u[5] ) {
				game_type = u[5];
			}
			
			CDB.userdata.push( 
				{
				name: u[0] ,  // CGSN.341345608567535   ref : hyungc
				'game': game_type, 
				'serverinfo': server_info,
				device: CDB.devices[em.device.iphone],
				device_code: u[3],		// random code 
				'password': passwd,
				castles: [],
				options : { sp30: true,  },
				ref: u[2],
				key: '',			// random  invalid .. 
			});
			

			// sp 30 action states  
			/*
							self.cstls[i].setUserCityInfo(cstlinfo);	// // {"id":3070,"name":"\ucc9c\uc0c1\uc131","landtype":3,"x":185,"y":53}, 
			self.cstls[i].updateRes(res);
			self.cstls[i].updateSols(sols);
			self.cstls[i].updateCdlist(cds);
			self.cstls[i].updateCityInfo(city);
			self.cstls[i].updateStudies(studies);
			*/
			// name , castles , step, sub : , 
			var states = {name : u[0], castles: [] ,  step: 1, sub: 1 , exist: true } ;
			self.user_states.push( states );
		});
	},
	
	userCnt: function() {
		return this.sp_users.length;
	},
	
	
	// 
	getUserStates: function(idx) {
		var user = this.sp_users[idx];
		if ( !user ) {
			debug.log(this, 'Invalid user Idx');
			return;
		}
		
		return this.getUserStatesByName(user[0]);
	}, 
	
	getUserStatesByName: function(username) {
		var found_u;
		$.each ( this.user_states , function(i, u) {
			if ( u.name == username ) {
				found_u = u;
				return false;
			}
		});
		
		return found_u; 
	}, 
	
	
	setUserStates: function(user_state) {
		var self = this;;
		$.each ( this.user_states , function(i, u) {
			if ( u.name == user_state.name ) {
				$.extend ( u , user_state);
			
				debug.log( self, ' Update Success::');
				return false;
			}
		});
	}, 
	
	getAllRefs: function(ref) {
		return this.refs;
	},
	setRefererGroup: function(ref) {
		var self = this;
		
		// replace sp_users with ref .. 
		var found_refs = this.refs.filter ( function (el) { return el.ref == ref;}) ;
		var found_ref  =  found_refs[0];
		if ( ! found_ref) { 	alert('no Matched Ref'); return; 		}
		
		this.sp_users = found_ref.users;
		
		// with sp_users
		this.makeUserDB();
		// update ui 
		$('#refname').text( ref + ':' +  found_ref.server	 );
	}, 
	
};




function CSPProxy () {
	this.cur_user_s = {};
	this.initalize();
};

CSPProxy.prototype  = {
	objName: 'CSPProxy',
	
	initalize: function() {
		
	},

	changeCurUser: function(user_states) {
		
		this.cur_user_s = user_states;
	},
	
	// start sp action s
	start_sp30 : function() {
		
		if ( ! this.cur_user_s.initQ ) {
			debug.log(this, 'Create Init Qst' , this.cur_user_s);
			this.cur_user_s.initQ = new CInitQuest();
		}
		
		// restart : later 
		// TODO :  restart ---  : stop & start or...  
		this.cur_user_s.initQ.initialize();		// get prev stored state
		
		debug.log(this, 'Start Init Qst Mode');
		
		this.cur_user_s.initQ.start();	
		
	},
	
};

$(document).ready(function() {

	// cbs 
		em.cbs= {};
		
		// for cstl move & wave 
		em.cbs.cstlmove1done = $.Callbacks( "unique stopOnFalse" );	
		em.cbs.cstlwavedone = $.Callbacks( "unique stopOnFalse" );
		
			
		// login new user : got new key 
		em.cbs.userlogin = $.Callbacks("unique stopOnFalse");
		
		// when completed select new user : start GM  -> new login : get system task api :: then fire . :  reset all prev datas  
		em.cbs.userchanged = $.Callbacks("unique stopOnFalse");
			// when start user change :  to notify free prev resource  
		em.cbs.startuserchange = $.Callbacks("unique stopOnFalse");
		
		// all hero list update
		em.cbs.heroupdate = $.Callbacks("unique stopOnFalse");
		// hnting avaliable h list update 
		em.cbs.warableHpdate = $.Callbacks("unique stopOnFalse");
		
		// hnt  : 1 da hnt 1 time end cb  for cals end time : decide next ctsl
		em.cbs.hntdone = $.Callbacks("unique stopOnFalse");
		// 1 cstl att is done !!
		em.cbs.autoCstlAttDone = $.Callbacks("unique stopOnFalse");  
		// update cstl 's sols '
		em.cbs.updatesols = $.Callbacks("unique stopOnFalse");
		
		// sols trained finished  
		em.cbs.soltraindone = $.Callbacks("unique stopOnFalse");
		
		// global contorl cb 
		em.cbs.forcestop = $.Callbacks("unique stopOnFalse");
		
		// timer for desc time info  
		em.cbs.sectimer = $.Callbacks("unique stopOnFalse");
		
		
	// global 
		// var users = CDB.users;//[ 'james', 'greate'];
		// var devices = CDB.devices;//['iphone', 'android' ] ;
		
	// em.cstlview = new CCstlView();
	// em.cstlview.initialize();

/*

	em.sp30view = new CSP30View();

	// sp30 mode . info -> sp30 view. 
	em.infoview = em.sp30view ;
	// em.infoview.initialize();
//	em.infoview.connected();	*/

		
	em.cstlmgr = new CCstlMgr();
	em.cstlmgr.cstlwave_initialize();



	em.query = new CQuery();
	em.query.initialize();

	em.util = new CUtil();
		
	em.tasks = new CTasks();
	
	em.worldDA = new CWorldDA();
	
	em.hntmgr = new CHuntMgr();
	em.hntmgr.initialize();
	
	em.controller = new CController();
	
	em.scaning = new CScaning();
	em.scaning.initialize();

	em.hdrinmgr = new CHDrinMgr();
	
	
	// start monotor !!
	em.jobmonitor.registerCBs();
	em.jobmonitor.startMonitor();

	



	em.spusermgr = new CSPUserMgr();
	
	em.spproxy = new CSPProxy();
	
	em.spactmgr = new CSpActionMgr();
	//======================= TEST code here ========================
	// set login defualt user 'Greateload' for test 
	// em.controller.login('Greateload');
		

	


	/*
		 set nav with ref names 
		 
	*/
	$.each ( em.spusermgr.getAllRefs() , function(i, r ) {
		//$('.menu li').eq(i).text( r.ref );
		$('.menu li').eq(i).find('a').text( r.ref );
	});
	

/*
	 install click handler 
*/

			
			// ref select 
		$('.menu li').click(function(e) {
			//Cancel the link behavior
			e.preventDefault();
			
			//Get the A tag
			console.log( this, $(this), $(this).text() );
			// var id = $(this).attr('href');
			console.log( e, e.target, e.target.text)	;	

			var referer = $(this).text();
	
			// stop cmd..  .. <-no : 1 more click start.. 
			if ( referer == 'stop') {
				em.cbs.forcestop.fire();
				em.controller.finishDone();
				em.jobmonitor.force_stop = false;
				return;
			}
			// start group of ref 
			debug.log( this, ' START REF GROUP ', referer);
			em.spusermgr.setRefererGroup( referer);
			 
		});
   
   
   		// start sp job  when load completed...  
   		
   			$('.container1').click(function(e) {
				em.curOp ^= em.Operation.SP30ACTION;
				
				//$("#id_btn_buytrade").toggleClass('control_modeon');
				
				if ( em.curOp & em.Operation.SP30ACTION) {
					// debug.log(this,  ' SP30ACTION clicked ' , em.curOp.toString(16) );
					
					debug.log( this, '::info  : ');
					
					em.jobmonitor.addJob( {name: 'SP30ACTION', fn: em.jobmonitor.doSP30Action, param: undefined });
					em.jobmonitor.doMonitor();
					return;
				}	else {
					debug.log(this,  ' Mode release  ' , em.curOp.toString(16));
				}	   		
			});
});
  





